﻿using System;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;

namespace BaseSet.Entity.Common.Regular
{
    /// <summary>
    /// 正则表达式
    /// </summary>
    public static class Regular
    {
        /// <summary>
        /// 获取内容中匹配指定正则表达式的内容
        /// </summary>
        /// <param name="content">内容</param>
        /// <param name="pattern">正则表达式</param>
        /// <returns>Match:匹配内容</returns>
        public static Match GetContentByReg(string content, string pattern)
        {
            return GetContentByReg(content, pattern, RegexOptions.IgnoreCase);
        }

        /// <summary>
        /// 获取内容中匹配指定正则表达式的内容
        /// </summary>
        /// <param name="content">内容</param>
        /// <param name="pattern">正则表达式</param>
        /// <param name="options">正则表达式匹配选项</param>
        /// <returns>Match:匹配内容</returns>
        public static Match GetContentByReg(string content, string pattern, RegexOptions options)
        {
            Regex r = new Regex(pattern, options);
            Match m = r.Match(content);
            return m;
        }

        /// <summary>
        /// 判断内容是否符合正则表达式
        /// </summary>
        /// <param name="content">内容</param>
        /// <param name="pattern">正则表达式</param>
        /// <returns>true:符合 flase:不符合</returns>
        public static bool IsMatch(string content, string pattern)
        {
            Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
            Match m = r.Match(content);
            return m.Success;
        }

    }
}
